-- This is the command to be invoked in the "on mouseUp" script of the
-- field (the field must be locked, of course).
on fieldHotFingers
put the optionKey into oKy
put the shiftKey into sKy
put the target into source
if (oKy is "down") AND (sKy is "down") then
showHotFingers source
exit fieldHotFingers
end if
-- put "char" into spec
put "word" into spec -- make this Word sensitive
put fieldClick(spec) into code
if sKy is "down" then
loadHotFinger code,source
else
hotFinger code,source
end if
end fieldHotFingers
-- This will tell us what character(s) were selected.
function fieldClick var
set the lockText of the target to false
if var="word" then click at the mouseLoc
click at the mouseLoc
put the selectedChunk into spott
set the lockText of the target to true
click at -1,-1 -- remove the selection hilite or insertion point
put word 2 of spott into cNum
if var="word" then
put word 4 of spott into cNum2
else
delete word 3 to 4 of spott
put cNum into cNum2
end if
if cnum2<cnum then
put cnum2 into cnum
put cnum into word 2 of spott
end if
put "put " before spott
put " into theChar" after spott
do spott
return cnum & "," & cnum2 & "," & theChar
end fieldClick
-- This will check to see it the selected characters are in a HotFingers
-- item.
on hotFinger
put param(1) into cNum
put item 2 of cNum into cNum2
put item 1 of cNum into cNum
put param(2) into fNam
put getHotLines(fNam) into workarea
put the number of lines of workArea into howMany
repeat with ii = 1 to howMany
put line ii of workArea into theLine
put offset(")",theLine) into spott
subtract 1 from spott
put char 5 to spott of theLine into theRange
put item 1 of theRange into test1
put item 2 of theRange into test2
if test2<test1 then put test1 into test2
if (cNum>=test1) AND (cNum2<=test2) then
add 1 to spott
delete char 1 to spott of theLine
do theLine
end if
end repeat
end hotFinger
-- This will let the user define a HotFingers area.
on loadHotFinger
set the cursor to 4
put param(1) into cNum
put item 2 of cNum into cNum2
put item 1 of cNum into cNum
put param(2) into fNam
put "put the script of" && fNam && "into workArea" into dom
do dom
put the number of lines of workArea into howMany
put "beep 5" into theCmd
repeat with ii = 1 to howMany
put line ii of workArea into theLine
if char 1 of theLine<>"-" then exit repeat
put offset(")",theLine) into spott
if spott<1 then exit repeat
subtract 1 from spott
put char 5 to spott of theLine into theRange
put item 1 of theRange into test1
put item 2 of theRange into test2
if test2<test1 then put test1 into test2
if (cNum>=test1) AND (cNum2<=test2) then
add 1 to spott
delete char 1 to spott of theLine
answer "That is already contained in " & theRange with ¬
"Show code" OR "Replace" OR "Cancel"
if it is "Show code" then
answer theLine with "Remove" OR "Replace" OR "Cancel"
end if
if it is "Cancel" then exit loadHotFinger
delete line ii of workArea
if it is "remove" then
put empty into theCmd
else
put theLine into theCmd
end if
exit repeat
end if
end repeat
if theCmd is NOT empty then
ask "What command:" with theCmd
if it is empty then exit loadHotFinger
put it into theLine
put "-- (" & cNum & "," & cNum2 & ") " before theLine
put theLine & return before workArea
end if
put "set the script of" && fNam && "to workArea" into dom
do dom
end loadHotFinger
-- This gets the command lines from the field script.
function getHotLines trg
put trg into fNam
put "put the script of" && fNam && "into workArea" into dom
do dom
put the number of lines of workArea into howMany
put empty into rslt
repeat with ii = 1 to howMany
if char 1 of line ii of workArea <> "-" then exit repeat
if line ii of workArea contains ")" then
put line ii of workarea into line ii of rslt
else
exit repeat
end if
end repeat
return rslt
end getHotLines
-- This will cycle through the defined HotFingers
on showHotFingers
put param(1) into fNam
put getHotLines(fNam) into workarea
put the number of lines of workArea into howMany
put 1 into ii
repeat forever
if the optionKey is "up" then exit repeat
if the shiftKey is "up" then exit repeat
put line ii of workArea into theLine
put offset(")",theLine) into spott
subtract 1 from spott
put char 5 to spott of theLine into theRange
put item 1 of theRange into test1
put item 2 of theRange into test2
if test2<test1 then put test1 into test2
set the lockText of fNam to false
put "char " & test1 & " to " & test2 & " of " & fNam into chunkExpr
select chunkExpr
set the lockText of the target to true
wait 20 ticks
add 1 to ii
if ii>howMany then put 1 into ii
end repeat
click at -1,-1 -- remove the selection hilite or insertion point
end showHotFingers
-- part contents for background part 5
----- text -----
8/29/88 13:39
-- part contents for background part 4
----- text -----
FieldHotFingers is a non-XCMD implementation of "hot" spots in a locked text field, i.e. areas of text that can be defined to act as buttons. This works even if the field is scrolled or if it's size is changed. However, if the actual text is changed, then the pointers to the "hot" areas will still point to the original locations.
Note: this tool requires HyperCard version 1.2 or greater.